<!--
  功能：考勤统计
  作者：licy
  邮箱：licy@briup.com
  时间：2020年12月08日 11:07:34
  版本：v1.0
  修改记录：
  修改内容：
  修改人员：
  修改时间：
-->
<template>
  <div class='clazz_attendance'>
    <div class="btns">
      <el-form inline size="small" style="text-align:center">
        <el-form-item>
          <el-select v-model="param.area" style="width:160px" clearable>
            <el-option label="鳗鲤湖基地" value="鳗鲤湖基地" ></el-option>
            <el-option label="浦东软件园基地" value="浦东软件园基地" ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select v-model="param.status" style="width:100px" clearable>
            <el-option label="未开班" value="未开班" ></el-option>
            <el-option label="正常" value="正常" ></el-option>
            <el-option label="结课" value="结课" ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-date-picker v-model="param.date" value-format="timestamp" type="date" placeholder="选择日期" />
        </el-form-item>
        <el-form-item>
          <el-radio-group v-model="param.stage">
            <el-radio label="上午">上午</el-radio>
            <el-radio label="下午">下午</el-radio>
            <el-radio label="晚自习">晚自习</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="loadClazzAttendances">搜索</el-button>
        </el-form-item>
      </el-form>
      
    </div>
    
    <el-table size="small" :data="clazzAttendances" v-loading="loading" border>
      <el-table-column label="序号" type="index" :index="1" fixed="left"></el-table-column>
      <el-table-column label="基地" prop="clazz.area" width="160" align="center" fixed="left"></el-table-column>
      <el-table-column label="班级" prop="clazz.name" width="260" align="center" fixed="left"></el-table-column>
      <el-table-column label="生源" prop="clazz.source" width="260" align="center"></el-table-column>
      <el-table-column label="开班时间" align="center" width="100"> 
        <template slot-scope="scope">
          {{scope.row.clazz.beginTime | fmtDate}}
        </template>
      </el-table-column>
      <el-table-column label="结课时间" align="center" width="100"> 
        <template slot-scope="scope">
          {{scope.row.clazz.endTime | fmtDate}}
        </template>
      </el-table-column>
      <el-table-column label="班主任" prop="chargeId" width="100" align="center"> 
        <template slot-scope="scope">
          <el-tag size="mini" type="success" v-if="scope.row.clazz.charge">{{scope.row.clazz.charge.realname}}</el-tag>
          <el-tag size="mini" type="danger" v-else>暂未指定</el-tag>
        </template>
      </el-table-column>
       <el-table-column label="教室" prop="chargeId" width="130" align="center"> 
        <template slot-scope="scope">
          <el-tag size="mini" type="success" v-if="scope.row.clazz.clazzRoom">{{scope.row.clazz.clazzRoom.name}}</el-tag>
          <el-tag size="mini" type="danger" v-else>暂未指定</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="主讲老师" prop="clazzLog.mainTeacher" width="80" align="center">
        <template slot-scope="scope">
          {{scope.row.clazzLog?scope.row.clazzLog.mainTeacher:""}}
        </template>
      </el-table-column>
      <el-table-column label="辅导老师" prop="clazzLog.assistTeacher" width="80" align="center">
        <template slot-scope="scope">
          {{scope.row.clazzLog?scope.row.clazzLog.assistTeacher:""}}
        </template>
      </el-table-column>
      <el-table-column label="学习课程" prop="clazzLog.course" width="220" align="center">
        <template slot-scope="scope">
          {{scope.row.clazzLog?scope.row.clazzLog.course:""}}
        </template>
      </el-table-column>
      <el-table-column label="总人数"  width="80" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.clazz">
            {{scope.row.clazz.total}}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="离校人数"  width="80" align="center">
        <template slot-scope="scope">
          {{scope.row.clazz?scope.row.clazz.leaveNum:""}}
        </template>
      </el-table-column>
      <el-table-column label="应到人数"  width="80" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.clazz">
            {{scope.row.clazz.total - scope.row.clazz.leaveNum}}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="缺勤人数"  width="80" align="center">
        <template slot-scope="scope">
          <el-tag size="mini" type="danger" v-if="scope.row.absenceNum>0">{{scope.row.absenceNum}}</el-tag>
          <el-tag size="mini" type="success" v-else>{{scope.row.absenceNum}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="实到人数"  width="80" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.clazz">
            {{(scope.row.clazz.total - scope.row.clazz.leaveNum)-scope.row.absenceNum}}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="考勤情况" prop="introduce" align="center" min-width="480"></el-table-column>
      <el-table-column label="备注" prop="clazzLog.comment" min-width="180" align="center">
        <template slot-scope="scope">
          {{scope.row.clazzLog?scope.row.clazzLog.comment:""}}
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { get } from '@/utils/request'
import qs from 'qs';
import {removeEmptyField} from '@/utils/objUtils'
export default {
  // 组件名称
  name: 'demo',
  // 组件参数 接收来自父组件的数据
  props: {},
  // 组件状态值
  data () {
   return {
     param:{
       status:'正常'
     },
     clazzAttendances:[],
     loading:false,
   }
  },
  // 计算属性
  computed: {},
  // 侦听器
  watch: {},
  // 组件方法
  methods: {
   
    loadClazzAttendances(){
      this.loading = true;
      let url = "/studentAttendance/queryClazzAttendance"
      let param = removeEmptyField(this.param);
      get(url,param).then(resp => {
        this.clazzAttendances = resp.data;
        this.loading = false;
      })
    },
    initParam(){
      let now = new Date();
      this.param.date = now.getTime();
      let stage = '上午';
      if(now.getHours() > 13 && now.getHours() < 18){
        stage = '下午';
      } else if(now.getHours() > 18) {
        stage = '晚自习';
      }
      this.param = {
        ...this.param,
        stage
      } ;
    }
  },
  // 以下是生命周期钩子
  /**
  * 组件实例创建完成，属性已绑定，但DOM还未生成，$ el属性还不存在
  */
  created () {
    this.initParam();
    this.loadClazzAttendances();
  },
  /**
  * el 被新创建的 vm.$ el 替换，并挂载到实例上去之后调用该钩子。
  * 如果 root 实例挂载了一个文档内元素，当 mounted 被调用时 vm.$ el 也在文档内。
  */
  mounted () {
  },
  /**
  * 实例销毁之前调用。在这一步，实例仍然完全可用。
  */
  beforeDestroy () {
  },
  /**
  * Vue 实例销毁后调用。调用后，Vue 实例指示的所有东西都会解绑定，
  * 所有的事件监听器会被移除，所有的子实例也会被销毁。
  */
  destroyed () {
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<!--使用了scoped属性之后，父组件的style样式将不会渗透到子组件中，-->
<!--然而子组件的根节点元素会同时被设置了scoped的父css样式和设置了scoped的子css样式影响，-->
<!--这么设计的目的是父组件可以对子组件根元素进行布局。-->
<style scoped>

</style>
